package cn.wen.action;

import java.io.ByteArrayInputStream;
import java.util.Map;

import cn.wen.util.IdentifyCodeUtil;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
* @ClassName: IdentifyAction
* @Description: 验证码 action
* @author Gavin Nie  
* @e-mail Nie_ZW@163.com
* @date 2014年7月5日 下午7:15:37
*/
public class IdentifyAction extends ActionSupport
{
	private static final long serialVersionUID = 1L;
	private ByteArrayInputStream inputStream;
	private String identifyCode;

	@Override
	public String execute() throws Exception
	{
		IdentifyCodeUtil image = new IdentifyCodeUtil();
		this.setInputStream(image.generteCode());// 取得带有随机字符串的图片

		// 设置到session中
		Map<String, Object> session = ActionContext.getContext().getSession();
		session.put("code", image.getCodeStr());

		return SUCCESS;
	}

	public ByteArrayInputStream getInputStream()
	{
		return inputStream;
	}

	public void setInputStream(ByteArrayInputStream inputStream)
	{
		this.inputStream = inputStream;
	}

	public String getIdentifyCode()
	{
		return identifyCode;
	}

	public void setIdentifyCode(String identifyCode)
	{
		this.identifyCode = identifyCode;
	}

}
